package com.sec.android.app.myfiles.util;

import android.content.Context;
import android.content.SharedPreferences;
import android.graphics.Point;
import android.preference.PreferenceManager;
import android.view.WindowManager;

import com.sec.android.app.myfiles.R;
import com.sec.android.app.myfiles.common.PickerActivity;
import com.sec.android.app.myfiles.feature.MultiWindowMgr;
import com.sec.android.app.myfiles.info.AppConstants;
import com.sec.android.app.myfiles.info.AppConstants.AppUpdateBadge;
import com.sec.android.app.myfiles.info.AppConstants.SortByOrder;
import com.sec.android.app.myfiles.info.AppConstants.SortByType;
import com.sec.android.app.myfiles.info.AppConstants.ViewType;
import com.sec.android.app.myfiles.info.MyFilesPreference.Key;
import com.sec.android.app.myfiles.log.Log;
import com.sec.android.app.myfiles.module.abstraction.FileRecord;
import com.sec.android.app.myfiles.module.cloud.CloudFileRecord;
import com.sec.android.app.myfiles.module.local.category.CategoryFileRecord;
import com.sec.android.app.myfiles.navigation.NavigationInfo;
import com.sec.android.app.myfiles.update.AppIconUpdateBadgeSetter;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import static android.preference.PreferenceManager.getDefaultSharedPreferences;
import static com.sec.android.app.myfiles.info.AppConstants.UNDEFINED;
import static com.sec.android.app.myfiles.info.MyFilesPreference.Key.Option.VIEW_TYPE_POSTFIX;
import static com.sec.android.app.myfiles.info.MyFilesPreference.Key.Option.VIEW_TYPE_PREFIX;

public class PreferenceUtils {

    private static final int TOTAL_WIDTH_RATE = 100;
    private static final int DEFUALT_RIGHT_RATE = 60;
    private static final int DEFAULT_UNUSED_PERIOD = 6;

    public enum ViewAsKey {
        Storage(VIEW_TYPE_PREFIX + "storage" + VIEW_TYPE_POSTFIX),
        Recent(VIEW_TYPE_PREFIX + "recent" + VIEW_TYPE_POSTFIX),
        Image(VIEW_TYPE_PREFIX + "image" + VIEW_TYPE_POSTFIX),
        Video(VIEW_TYPE_PREFIX + "video" + VIEW_TYPE_POSTFIX),
        Audio(VIEW_TYPE_PREFIX + "audio" + VIEW_TYPE_POSTFIX),
        Document(VIEW_TYPE_PREFIX + "document" + VIEW_TYPE_POSTFIX),
        Download(VIEW_TYPE_PREFIX + "download" + VIEW_TYPE_POSTFIX),
        APK(VIEW_TYPE_PREFIX + "apk" + VIEW_TYPE_POSTFIX),
        GoogleDrive(VIEW_TYPE_PREFIX + "googledrive" + VIEW_TYPE_POSTFIX),
        SamsungDrive(VIEW_TYPE_PREFIX + "samsungdrive" + VIEW_TYPE_POSTFIX);

        private String mKey;

        ViewAsKey(String key) {
            mKey = key;
        }

        public String getKey() {
            return mKey;
        }
    }

    public static int getSortByType(Context context, NavigationInfo naviInfo) {
        int sortByType = getDefaultSortBy(naviInfo);
        if (sortByType == SortByType.NAME)
            return getDefaultSharedPreferences(context).getInt(Key.Option.SORT_BY_TYPE_FOLDER, sortByType);
        else
            return getDefaultSharedPreferences(context).getInt(Key.Option.SORT_BY_TYPE_CATEGORY, sortByType);
    }

    public static void setSortByType(Context context, NavigationInfo naviInfo, int value) {
        SharedPreferences.Editor e = getDefaultSharedPreferences(context).edit();
        if (getDefaultSortBy(naviInfo) == SortByType.NAME)
            e.putInt(Key.Option.SORT_BY_TYPE_FOLDER, value);
        else
            e.putInt(Key.Option.SORT_BY_TYPE_CATEGORY, value);
        e.apply();
    }

    public static int getSortByOrder(Context context, NavigationInfo naviInfo) {
        if (getDefaultSortBy(naviInfo) == SortByType.NAME) {
            return getDefaultSharedPreferences(context).getInt(Key.Option.SORT_BY_ORDER_FOLDER, SortByOrder.ASC);
        } else {
            return getDefaultSharedPreferences(context).getInt(Key.Option.SORT_BY_ORDER_CATEGORY, SortByOrder.DESC);
        }
    }

    public static void setSortByOrder(Context context, NavigationInfo naviInfo, int value) {
        SharedPreferences.Editor e = getDefaultSharedPreferences(context).edit();
        if (getDefaultSortBy(naviInfo) == SortByType.NAME) {
            e.putInt(Key.Option.SORT_BY_ORDER_FOLDER, value);
        } else {
            e.putInt(Key.Option.SORT_BY_ORDER_CATEGORY, value);
        }
        e.apply();
    }

    public static ViewAsKey getViewAsKey(FileRecord curRecord) {
        ViewAsKey ret = ViewAsKey.Storage;

        if (curRecord != null) {
            FileRecord.StorageType storageType = curRecord.getStorageType();
            if (storageType == FileRecord.StorageType.Local) {
                ret = ViewAsKey.Storage;
            } else if (storageType == FileRecord.StorageType.Recent) {
                ret = ViewAsKey.Recent;
            } else if (storageType == FileRecord.StorageType.Cloud) {
                FileRecord.CloudType curCloud = ((CloudFileRecord) curRecord).getCloudType();
                if (curCloud == FileRecord.CloudType.GoogleDrive) {
                    ret = ViewAsKey.GoogleDrive;
                } else if (curCloud == FileRecord.CloudType.SamsungDrive) {
                    ret = ViewAsKey.SamsungDrive;
                }
            } else if (storageType == FileRecord.StorageType.Category) {
                FileRecord.CategoryType curCategory = ((CategoryFileRecord) curRecord).getCategoryType();
                if (curCategory != FileRecord.CategoryType.None) {
                    if (curCategory == FileRecord.CategoryType.Image) {
                        ret = ViewAsKey.Image;
                    } else if (curCategory == FileRecord.CategoryType.Video) {
                        ret = ViewAsKey.Video;
                    } else if (curCategory == FileRecord.CategoryType.Audio) {
                        ret = ViewAsKey.Audio;
                    } else if (curCategory == FileRecord.CategoryType.Document) {
                        ret = ViewAsKey.Document;
                    } else if (curCategory == FileRecord.CategoryType.Apk) {
                        ret = ViewAsKey.APK;
                    }
                }
            } else if (storageType == FileRecord.StorageType.Downloads) {
                ret = ViewAsKey.Download;
            } else if (storageType == FileRecord.StorageType.Trash) {
                ret = ViewAsKey.SamsungDrive;
            }
        }
        return ret;
    }

    public static ViewAsKey getViewAsKey(NavigationInfo naviInfo) {
        ViewAsKey ret = ViewAsKey.Storage;
        if (naviInfo != null) {
            Log.d("myfiles", "createListView");
            if (naviInfo.isSingleAudioPickerMode()) {
                ret = ViewAsKey.Audio;
            } else {
                ret = getViewAsKey(naviInfo.getCurRecord());
            }
        }
        return ret;
    }

    public static int getViewAs(Context context, ViewAsKey viewAsKey) {
        return getDefaultSharedPreferences(context).getInt(viewAsKey.getKey(), ViewType.LIST_DETAIL);
    }

    public static void setViewAs(Context context, int value, ViewAsKey viewAsKey) {
        SharedPreferences.Editor e = getDefaultSharedPreferences(context).edit();
        e.putInt(viewAsKey.getKey(), value);
        e.apply();
    }

    public static boolean getShowHiddenFiles(Context context) {
        return getDefaultSharedPreferences(context).getBoolean(Key.Option.SHOW_HIDDEN_FILES, false);
    }

    public static void setShowHiddenFiles(Context context, boolean value) {
        SharedPreferences.Editor e = getDefaultSharedPreferences(context).edit();
        e.putBoolean(Key.Option.SHOW_HIDDEN_FILES, value);
        e.apply();
    }

    public static void setPreviousTheme(Context context, String value) {
        SharedPreferences.Editor e = getDefaultSharedPreferences(context).edit();
        e.putString(Key.Option.PREVIOUS_THEME, value);
        e.apply();
    }

    public static String getPreviousTheme(Context context) {
        return getDefaultSharedPreferences(context).getString(Key.Option.PREVIOUS_THEME, null);
    }

    public static void setColumnListWidth(Context context, MultiWindowMgr.WindowState winState, int index, int width) {
        MultiWindowMgr.WindowState orient = MultiWindowMgr.WindowState.PORTRAIT;
        if (winState == MultiWindowMgr.WindowState.LANDSCAPE) {
            orient = winState;
        }

        int activityType = AppConstants.ActivityType.FILE_LIST_ACTIVITY;

        SharedPreferences.Editor e = getDefaultSharedPreferences(context).edit();
        e.putInt(Key.Option.COLUMN_LIST_WIDTH + orient + index + activityType, width);
        e.apply();
    }

    public static int getColumnListWidth(Context context, MultiWindowMgr.WindowState winState, int index) {
        int columnIndexWidth = 18;
        int nameColumnIndexWidth = 46;
        int activityType;
        int rightPanelSize;

        MultiWindowMgr.WindowState orient = MultiWindowMgr.WindowState.PORTRAIT;

        if (winState == MultiWindowMgr.WindowState.LANDSCAPE) {
            orient = winState;
        }

        WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
        Point size = new Point();
        wm.getDefaultDisplay().getSize(size);

        activityType = AppConstants.ActivityType.FILE_LIST_ACTIVITY;
        rightPanelSize = size.x * DEFUALT_RIGHT_RATE / TOTAL_WIDTH_RATE;

        if (context instanceof PickerActivity) {
            activityType = AppConstants.ActivityType.PICKER_ACTIVITY;
            rightPanelSize = context.getResources().getDimensionPixelSize(R.dimen.picker_popup_width);
        }

        int columnHeaderWidth = rightPanelSize
                - context.getResources().getDimensionPixelSize(R.dimen.list_column_side_margin) * 2
                - context.getResources().getDimensionPixelSize(R.dimen.list_column_header_divider_width) * 4;

        int nameHeaderWidth = (columnHeaderWidth * nameColumnIndexWidth / (columnIndexWidth * 3 + nameColumnIndexWidth));
        int otherHeaderWidth = (columnHeaderWidth * columnIndexWidth / (columnIndexWidth * 3 + nameColumnIndexWidth));
        int defaultWidth[] = {
                nameHeaderWidth,
                otherHeaderWidth,
                otherHeaderWidth,
                columnHeaderWidth - nameHeaderWidth - otherHeaderWidth * 2
        };

        return getDefaultSharedPreferences(context).getInt(Key.Option.COLUMN_LIST_WIDTH + orient + index + activityType, defaultWidth[index]);
    }

    public static int getGridViewPinchDepth(Context context) {
        int ret = getDefaultSharedPreferences(context).getInt(Key.Option.GRID_VIEW_PINCH_DEPTH, 2);
        if (UiUtils.isCategoryFolderList(context)) {
            ret = getDefaultSharedPreferences(context).getInt(Key.Option.GRID_VIEW_PINCH_DEPTH_CATERGORY_FOLDER_LIST, 1);
        }
        return ret;
    }

    public static void setGridViewPinchDepth(Context context, int pinchDepth) {
        SharedPreferences.Editor e = getDefaultSharedPreferences(context).edit();
        if (UiUtils.isCategoryFolderList(context)) {
            e.putInt(Key.Option.GRID_VIEW_PINCH_DEPTH_CATERGORY_FOLDER_LIST, pinchDepth);
        } else {
            e.putInt(Key.Option.GRID_VIEW_PINCH_DEPTH, pinchDepth);
        }
        e.apply();
    }

    public static boolean getShowSecureFolderTipCard(Context context) {
        return getDefaultSharedPreferences(context).getBoolean(Key.Option.SECURE_FOLDER_TIP_CARD, true);
    }

    public static void setShowSecureFolderTipCard(Context context, boolean value) {
        SharedPreferences.Editor e = getDefaultSharedPreferences(context).edit();
        e.putBoolean(Key.Option.SECURE_FOLDER_TIP_CARD, value);
        e.apply();
    }

    public static long getLargeFilesSize(Context context) {
        return getDefaultSharedPreferences(context).getLong(Key.Option.LARGE_FILES_SIZE, 25 * FileUtils.MEGA_BYTES);
    }

    public static void setLargeFilesSize(Context context, Long size) {
        SharedPreferences.Editor e = getDefaultSharedPreferences(context).edit();
        e.putLong(Key.Option.LARGE_FILES_SIZE, size);
        e.apply();
    }

    public static int getUnusedFilesPeriod(Context context) {
        return getDefaultSharedPreferences(context).getInt(Key.Option.UNUSED_FILES_PERIOD, DEFAULT_UNUSED_PERIOD);
    }

    public static void setUnusedFilesPeriod(Context context, int period) {
        SharedPreferences.Editor e = getDefaultSharedPreferences(context).edit();
        e.putInt(Key.Option.UNUSED_FILES_PERIOD, period);
        e.apply();
    }

    public static List<Integer> getCustomLargeFilesSize(Context context) {
        Set<String> values = PreferenceManager.getDefaultSharedPreferences(context)
                .getStringSet(Key.Option.CUSTOM_LARGE_FILES_SIZE, null);
        return convertStringSetToIntegerList(values);
    }

    public static void setCustomLargeFileSize(Context context, List<Integer> values) {
        Set<String> set = convertIntegerListToStringSet(values);
        if (set != null) {
            SharedPreferences.Editor e = getDefaultSharedPreferences(context).edit();
            e.putStringSet(Key.Option.CUSTOM_LARGE_FILES_SIZE, set);
            e.apply();
        }
    }

    public static List<Integer> getCustomUnusedFilesPeriod(Context context) {
        Set<String> values = PreferenceManager.getDefaultSharedPreferences(context)
                .getStringSet(Key.Option.CUSTOM_UNUSED_FILES_PERIOD, null);
        return convertStringSetToIntegerList(values);
    }

    public static void setCustomUnusedFilePeriod(Context context, List<Integer> values) {
        Set<String> set = convertIntegerListToStringSet(values);
        if (set != null) {
            SharedPreferences.Editor e = getDefaultSharedPreferences(context).edit();
            e.putStringSet(Key.Option.CUSTOM_UNUSED_FILES_PERIOD, set);
            e.apply();
        }
    }

    private static Set<String> convertIntegerListToStringSet(List<Integer> values) {
        Set<String> ret = null;
        if (values != null && !values.isEmpty()) {
            ret = new HashSet<>();
            for (Integer value : values) {
                ret.add(value.toString());
            }
        }
        return ret;
    }

    private static List<Integer> convertStringSetToIntegerList(Set<String> values) {
        List<Integer> ret = null;
        if (values != null && !values.isEmpty()) {
            ret = new ArrayList<>();
            for (String value : values) {
                ret.add(Integer.valueOf(value));
            }
        }
        return ret;
    }

    public static void setNotificationAlarmInterval(Context context, long interval) {
        SharedPreferences.Editor e = PreferenceManager.getDefaultSharedPreferences(context).edit();
        e.putLong(Key.Option.NOTIFICATION_ALARM_INTERVAL, interval);
        e.apply();
    }

    public static long getNotificationAlarmInterval(Context context) {
        return PreferenceManager.getDefaultSharedPreferences(context).getLong(Key.Option.NOTIFICATION_ALARM_INTERVAL, 0L);
    }

    public static void setNotificationActionType(Context context, int type) {
        SharedPreferences.Editor e = PreferenceManager.getDefaultSharedPreferences(context).edit();
        e.putInt(Key.Option.NOTIFICATION_ACTION_TYPE, type);
        e.apply();
    }

    public static int getNotificationActionType(Context context) {
        return PreferenceManager.getDefaultSharedPreferences(context).getInt(Key.Option.NOTIFICATION_ACTION_TYPE,
                AppConstants.NotificationActionType.REPEAT_ONE_HOUR);
    }

    private static int getDefaultSortBy(NavigationInfo naviInfo) {
        int sortBy = SortByType.NAME;
        if (naviInfo != null) {
            FileRecord curRecord = naviInfo.getCurRecord();
            if (curRecord != null) {
                FileRecord.StorageType storageType = curRecord.getStorageType();
                switch (storageType) {
                    case Downloads:
                    case Recent:
                    case Category:
                        sortBy = SortByType.TIME;
                        break;
                    default:
                        break;
                }
            }
        }
        return sortBy;
    }

    public static void setMoreOptionBadgeIcon(Context context, boolean value) {
        SharedPreferences.Editor e = PreferenceManager.getDefaultSharedPreferences(context).edit();
        e.putBoolean(Key.Option.SHOW_MORE_OPTION_BADGE_ICON, value);
        e.apply();
    }

    public static boolean getMoreOptionBadgeIcon(Context context) {
        return PreferenceManager.getDefaultSharedPreferences(context).getBoolean(Key.Option.SHOW_MORE_OPTION_BADGE_ICON, true);
    }

    public static void setPackageDataCleared(Context context, boolean value) {
        SharedPreferences.Editor e = PreferenceManager.getDefaultSharedPreferences(context).edit();
        e.putBoolean(Key.Option.PACKAGE_DATA_CLEARED, value);
        e.apply();
    }

    public static boolean getPackageDataCleared(Context context) {
        return PreferenceManager.getDefaultSharedPreferences(context).getBoolean(Key.Option.PACKAGE_DATA_CLEARED, true);
    }

    public static void setFirstEntry(Context context, boolean value) {
        SharedPreferences.Editor e = PreferenceManager.getDefaultSharedPreferences(context).edit();
        e.putBoolean(Key.Option.IS_FIRST_ENTRY, value);
        e.apply();
    }

    public static boolean isFirstEntry(Context context) {
        return PreferenceManager.getDefaultSharedPreferences(context).getBoolean(Key.Option.IS_FIRST_ENTRY, true);
    }

    public static void setLatestVersion(Context context, int versionCode, boolean isMyFiles) {
        SharedPreferences.Editor e = PreferenceManager.getDefaultSharedPreferences(context).edit();
        String key = isMyFiles ? Key.Option.MYFILES_LATETEST_VERSION : Key.Option.CLOUDGATEWAY_LATETEST_VERSION;
        e.putInt(key, versionCode);
        e.apply();
    }

    public static int getLatestVersion(Context context, int versionCode, boolean isMyFiles) {
        String key = isMyFiles ? Key.Option.MYFILES_LATETEST_VERSION : Key.Option.CLOUDGATEWAY_LATETEST_VERSION;
        return PreferenceManager.getDefaultSharedPreferences(context).getInt(key, versionCode);
    }

    public static void setLastUpdateDate(Context context, long date) {
        SharedPreferences.Editor e = PreferenceManager.getDefaultSharedPreferences(context).edit();
        e.putLong(Key.Option.LASTUPDATE_CHECK_DATE, date);
        e.apply();
    }

    public static long getLastUpdateDate(Context context, long value) {
        return PreferenceManager.getDefaultSharedPreferences(context).getLong(Key.Option.LASTUPDATE_CHECK_DATE, value);
    }

    public static void setAvailAppUpdate(Context context, boolean value) {
        SharedPreferences.Editor e = PreferenceManager.getDefaultSharedPreferences(context).edit();
        e.putBoolean(Key.Option.AVAIL_APP_UPDATE, value);
        e.apply();
    }

    public static boolean getAvailAppUpdate(Context context) {
        return PreferenceManager.getDefaultSharedPreferences(context).getBoolean(Key.Option.AVAIL_APP_UPDATE, false);
    }

    public static void setBadgeCount(Context context, int value) {
        SharedPreferences.Editor e = PreferenceManager.getDefaultSharedPreferences(context).edit();
        e.putInt(Key.Option.APP_UPDATE_BADGE_COUNT, value);
        e.apply();

        if (value == AppUpdateBadge.EXIST_NEW_APP_UPDATE) {
            AppIconUpdateBadgeSetter.setBadge(context, AppUpdateBadge.EXIST_NEW_APP_UPDATE);
            PreferenceUtils.setAvailAppUpdate(context, true);
        } else {
            AppIconUpdateBadgeSetter.clearBadge(context);
            PreferenceUtils.setAvailAppUpdate(context, false);
        }
    }

    public static int getBadgeCount(Context context) {
        return PreferenceManager.getDefaultSharedPreferences(context).getInt(Key.Option.APP_UPDATE_BADGE_COUNT, UNDEFINED);
    }

    public static void setChinaURL(Context context, String value) {
        SharedPreferences.Editor e = PreferenceManager.getDefaultSharedPreferences(context).edit();
        e.putString(Key.Option.CHINA_APPS_URL, value);
        e.apply();
    }

    public static String getChinaURL(Context context, String value) {
        return PreferenceManager.getDefaultSharedPreferences(context).getString(Key.Option.CHINA_APPS_URL, value);
    }

    public static void setChinaURLUpdateDate(Context context, long date) {
        SharedPreferences.Editor e = PreferenceManager.getDefaultSharedPreferences(context).edit();
        e.putLong(Key.Option.CHINA_APPS_URL_CHECK_DATE, date);
        e.apply();
    }

    public static long getChinaURLUpdateDate(Context context, long date) {
        return PreferenceManager.getDefaultSharedPreferences(context).getLong(Key.Option.CHINA_APPS_URL_CHECK_DATE, date);
    }

    public static boolean getShowRecentFiles(Context context) {
        boolean bRet = true;
        if (context != null) {
            bRet = getDefaultSharedPreferences(context).getBoolean(Key.Option.SHOW_RECENT_FILES, true);
        }
        return bRet;
    }

    public static void setShowRecentFiles(Context context, boolean value) {
        SharedPreferences.Editor e = getDefaultSharedPreferences(context).edit();
        e.putBoolean(Key.Option.SHOW_RECENT_FILES, value);
        e.apply();
    }

    public static int[] getGmsPortraitLocation(Context context) {
        int location[] = new int[2];

        location[0] = getDefaultSharedPreferences(context).getInt(Key.Option.GMS_TIP_PORTRAIT_X, 0);
        location[1] = getDefaultSharedPreferences(context).getInt(Key.Option.GMS_TIP_PORTRAIT_Y, 0);
        return location;
    }

    public static void setGmsPortraitLocation(Context context, int location[]) {
        SharedPreferences.Editor e = getDefaultSharedPreferences(context).edit();
        e.putInt(Key.Option.GMS_TIP_PORTRAIT_X, location[0]);
        e.putInt(Key.Option.GMS_TIP_PORTRAIT_Y, location[1]);
        e.apply();
    }

    public static int[] getGmsLandscapeLocation(Context context) {
        int location[] = new int[2];

        location[0] = getDefaultSharedPreferences(context).getInt(Key.Option.GMS_TIP_LANDSCAPE_X, 0);
        location[1] = getDefaultSharedPreferences(context).getInt(Key.Option.GMS_TIP_LANDSCAPE_Y, 0);
        return location;
    }

    public static void setGmsLandscapeLocation(Context context, int location[]) {
        SharedPreferences.Editor e = getDefaultSharedPreferences(context).edit();
        e.putInt(Key.Option.GMS_TIP_LANDSCAPE_X, location[0]);
        e.putInt(Key.Option.GMS_TIP_LANDSCAPE_Y, location[1]);
        e.apply();
    }

    public static boolean getGmsVisitFlag(Context context) {
        return getDefaultSharedPreferences(context).getBoolean(Key.Option.GMS_VISIT_FLAG, false);
    }

    public static void setGmsVisitFlag(Context context) {
        SharedPreferences.Editor e = getDefaultSharedPreferences(context).edit();
        e.putBoolean(Key.Option.GMS_VISIT_FLAG, true);
        e.apply();
    }

    public static boolean getCloudVisitFlag(Context context) {
        return getDefaultSharedPreferences(context).getBoolean(Key.Option.CLOUD_VISIT_FLAG, false);
    }

    public static void setCloudVisitFlag(Context context) {
        SharedPreferences.Editor e = getDefaultSharedPreferences(context).edit();
        e.putBoolean(Key.Option.CLOUD_VISIT_FLAG, true);
        e.apply();
    }

    public static boolean[] getGmsTipConditionPool(Context context) {
        boolean conditionCheck[] = new boolean[3];

        conditionCheck[0] = getDefaultSharedPreferences(context).getBoolean(Key.Option.GMS_TIP_FIRST, false);
        conditionCheck[1] = getDefaultSharedPreferences(context).getBoolean(Key.Option.GMS_TIP_SECOND, false);
        conditionCheck[2] = getDefaultSharedPreferences(context).getBoolean(Key.Option.GMS_TIP_THIRD, false);
        return conditionCheck;
    }

    public static void setGmsTipConditionPool(Context context, boolean condition[]) {
        SharedPreferences.Editor e = getDefaultSharedPreferences(context).edit();
        e.putBoolean(Key.Option.GMS_TIP_FIRST, condition[0]);
        e.putBoolean(Key.Option.GMS_TIP_SECOND, condition[1]);
        e.putBoolean(Key.Option.GMS_TIP_THIRD, condition[2]);
        e.apply();
    }

    public static boolean[] getCloudTipConditionPool(Context context) {
        boolean conditionCheck[] = new boolean[3];

        conditionCheck[0] = getDefaultSharedPreferences(context).getBoolean(Key.Option.CLOUD_TIP_FIRST, false);
        conditionCheck[1] = getDefaultSharedPreferences(context).getBoolean(Key.Option.CLOUD_TIP_SECOND, false);
        conditionCheck[2] = getDefaultSharedPreferences(context).getBoolean(Key.Option.CLOUD_TIP_THIRD, false);
        return conditionCheck;
    }

    public static void setCloudTipConditionPool(Context context, boolean condition[]) {
        SharedPreferences.Editor e = getDefaultSharedPreferences(context).edit();
        e.putBoolean(Key.Option.CLOUD_TIP_FIRST, condition[0]);
        e.putBoolean(Key.Option.CLOUD_TIP_SECOND, condition[1]);
        e.putBoolean(Key.Option.CLOUD_TIP_THIRD, condition[2]);
        e.apply();
    }

    public static void setPreviousTipState(Context context, int state) {
        SharedPreferences.Editor e = getDefaultSharedPreferences(context).edit();
        e.putInt(Key.Option.PREVIOUS_TIP_STATE, state);
        e.apply();
    }

    public static int getPreviousTipState(Context context) {
        return getDefaultSharedPreferences(context).getInt(Key.Option.PREVIOUS_TIP_STATE, 0); // 0 means STATE_DISMISSED
    }

    public static void setPreviousTipType(Context context, int type) {
        SharedPreferences.Editor e = getDefaultSharedPreferences(context).edit();
        e.putInt(Key.Option.PREVIOUS_TIP_TYPE, type);
        e.apply();
    }

    public static int getPreviousTipType(Context context) {
        return getDefaultSharedPreferences(context).getInt(Key.Option.PREVIOUS_TIP_TYPE, 0); // 0 means GMS, 1 means CLOUD
    }

    public static boolean getDoNotShowDataUsagePopup(Context context) {
        return getDefaultSharedPreferences(context).getBoolean(Key.Option.DO_NOT_SHOW_DATA_USAGE_POPUP, false);
    }

    public static void setDoNotShowDataUsagePopup(Context context, boolean value) {
        SharedPreferences.Editor e = getDefaultSharedPreferences(context).edit();
        e.putBoolean(Key.Option.DO_NOT_SHOW_DATA_USAGE_POPUP, value);
        e.apply();
    }

    public static boolean getExtremelyFullCondition(Context context) {
        return getDefaultSharedPreferences(context).getBoolean(Key.Option.EXTREMELY_FULL_CONDITION, false);
    }

    public static void setExtremelyFullCondition(Context context, boolean result) {
        SharedPreferences.Editor e = getDefaultSharedPreferences(context).edit();
        e.putBoolean(Key.Option.EXTREMELY_FULL_CONDITION, result);
        e.apply();
    }

    public static int getMyFilesShortcutCount(Context context) {
        return getDefaultSharedPreferences(context).getInt(Key.Option.SHORTCUT_COUNT, 0);
    }

    public static void setMyFilesShortcutCount(Context context, int changed) {
        SharedPreferences sp = getDefaultSharedPreferences(context);
        SharedPreferences.Editor e = sp.edit();
        e.putInt(Key.Option.SHORTCUT_COUNT, sp.getInt(Key.Option.SHORTCUT_COUNT, 0) + changed);
        e.apply();
    }

    public static int getSupportNotificationPackage(Context context) {
        return getDefaultSharedPreferences(context).getInt(Key.Option.SUPPORT_NOTIFICATION_PACKAGE, -1);
    }

    public static void setSupportNotificationPackage(Context context, int result) {
        SharedPreferences.Editor e = getDefaultSharedPreferences(context).edit();
        e.putInt(Key.Option.SUPPORT_NOTIFICATION_PACKAGE, result);
        e.apply();
    }

}
